1
I’m trying to move from mysql to Pdo but do not understand how to step that mysql_result to Pdo, I appreciate any help made available
$limite = 10;
$SQL_COUNT = mysql_query("SElECT COUNT('id') FROM anuncios WHERE categoria='$categoria' AND estado=1");
$SQL_RESULT = ceil(mysql_result($SQL_COUNT, 0) / $limite);
$pg = (isset($_GET["pg"])) ? (int)$_GET["pg"] : 1;
$start = ($pg -1) * $limite;
I haven’t tested but assuming you already have the PDO configured try the following:
$limite = 10;
$stmt = $conn->prepare("SElECT COUNT('id') FROM anuncios WHERE categoria=:categoria AND estado=1");
$stmt->bindValue(':categoria', $categoria);
$stmt->execute();
$result = ceil($stmt->fetchColumn() / $limite);
$pg = (isset($_GET["pg"])) ? (int)$_GET["pg"] : 1;
$start = ($pg -1) * $limite;
– Rafael Withoeft
He spoke about configuring PDO, I did not configure anything, it is necessary some configuration in xampp or any online storage server?
– Pedro Piloto
Yes, you need to enable two extensions in your
php.ini {extension=php_pdo.dll - extension=php_pdo_mysql.dll}
and then establish your connection where you wish($con = new PDO("mysql:host=localhost;dbname=exercicio", "root", "senha"); )
On this site you can find more information if you have any questions: http://ademir.winponta.com.br/php-pdo-mysql-carregando-configurando/– Rafael Withoeft
Thanks for the information, I only have to configure in case I use local server, when I upload the site to a host, I have to make a change or normal servers support Pdo?
– Pedro Piloto
I believe that almost all accept PDO. Otherwise you can contact the support of the chosen hosting for more information...
– Rafael Withoeft
Okay, thank you so much for your help
– Pedro Piloto