Jump to content

[SOLVED] mysql to mysqli migrationproblems...


lots_o_nuts

Recommended Posts

Since mysqli should be safer then mysql i started transforming my code to the new situation, the only problem is that after many hours of frustration it still isn't working...

 

The required information:

 

SQL-server version: mysql-server.i386-5.0.45-4.fc8

PHP-version: php.i386-5.2.4-3

 

I am using the php/mysql combo in a CMS, and the table i extract the data from has the following form:

 

pageidpagenamehtml

1home<B>some html code</B>

 

Now with mysql i used the following code to return the html-code:

 

<?php
$con =mysql_connect("***","***","***");
if ($con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("database",$con);
if(empty($_GET['pageid']))
{
$pageid = 1;
}
else
{
$pageid =_GET['pageid'];
}
$query = "SELECT html FROM pages WHERE pageid=" . $pageid;
$result = mysql_query($query);
$html = mysql_fetch_array($result);
echo $html['html'];
mysql_close($con);
?>

 

Now this gives me, as expected

 

<B>some html code</B>

 

when pageid is 1.

 

But when i try to implement the code according to the article on http://devzone.zend.com/node/view/id/686, and especially the "Using Bound Parameters and Bound Results Together" example, the following code:

 

<?php
$pageid = 1;
$mysqli = new mysqli('***', '***', '***', 'database');
if (mysqli_connect_errno()) 
{
printf("Can't connect to MySQL Server. Errorcode: %s\n", mysqli_connect_error());
exit;
}
if ($stmt = $mysqli->prepare('SELECT html FROM pages WHERE pageid = ?'))
{
$stmt->bind_param("i", $pageid);
$stmt->execute();
$stmt->bind_result($row);
$stmt->fetch();
var_dump($row);
$stmt->close();
}
$mysqli->close();
?>

 

gives me

 

string(0) ""

 

as output. I have no php errors/warnings/notices whatsoever, and mysql also isn't giving my any errors. What am i doing wrong?

 

If more information is needed, please say so.

 

--LoN

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.