Problem with PDO connection and mysql_query

1

Hello, I created the connection.php file as follows:

   <?
   $conn= new PDO("mysql:host=localhost;dbname=site", "root", "");

   $count = ('SELECT * FROM conteudo');
   $stmt = $conn->prepare($count);

   $stmt->execute();
   $result = $stmt->fetch(PDO::FETCH_ASSOC);
   return $result;
   ?>

And here I only give the include of the connection.php file?

    <?php include "conexao.php"; ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Contentype" content="text/html; charset=iso-8859-1" />
    <title> Painel Adm. Conteudo</title>
    <script type="text/javascript" src="//code.jquery.com/jquery-1.9.1.js"></script>
    <link rel="stylesheet" type="text/css" href="/css/normalize.css">
    <script type="text/javascript" src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script><linkrel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css">
    <link rel="stylesheet" type="text/css" href="/css/result-light.css">
    </head>
    <body>

    <div id="texto001" align="left" style=" font-family:Verdana, Geneva, sans-serif;
    color:#000000; font-size:12px; float:none; width:<? echo $res['larg_tex001'];?>px; 
    height:<? echo $res['altu_tex001'];?>; position: absolute; left: <? echo $res['hori_tex001'];?>px;
    top: <? echo $res['vert_tex001'];?>px;">

    <img align="left" src="upload/esp_texto.png" /> <?php echo $res['texto001'];?>
    </div>

    <img width="<? echo $res['larg_img001'];?>" height="<? echo $res['altu_img001'];?>" 
    align="left" src="upload/<? echo $res['img001'];?>" style="position: absolute; 
    left: <? echo $res['hori_img001'];?>px; top: <? echo $res['vert_img001'];?>px;" />

    </body>
    </html>

But I'm getting the following message below:

I ask friends what is missing to work on WAMPSERVER? If friends can help me solve this problem, I'll be very grateful. Hugs to all, and waiting for your help.

    
asked by anonymous 08.05.2015 / 05:21

2 answers

1

Create a connection:

$conn= new PDO("mysql:host=HOST;dbname=NOMEDOBD", "USUARIO", "SENHA");

Create a statement:

$count = 'SELECT COUNT(*) FROM livro';
$stmt = $conn->prepare($count);

and execute the statement:

$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
return $result;
    
08.05.2015 / 14:26
0

You are not making a connection to PDO, but to mysql.

The message says that the mysql_connect() function is deprecated, and that it will be removed from PHP. Ideally you should use PDO or mysqli .

A simple example of connecting to PDO:

$conexao = new PDO("mysql:host=HOST;dbname=NOMEDOBD", "USUARIO", "SENHA"); 
    
08.05.2015 / 05:29