Jump to content

help with connection to mysqli !


mekha

Recommended Posts

i have this connection:

<?php$dbhost = 'localhost';$dbuser = 'zzzz_u';$dbpass = 'zzzzzzz';$dbname = 'zzzz_db';  	$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);/* check connection */if ($mysqli->connect_errno) {	echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;	 } $mysqli->query("SET NAMES 'utf8' COLLATE 'utf8_general_ci'");?>

...and site_queries.php:

[/color]<?php		function getfrompages()		{				$sqlStr = "select * from tbl_pages where page_id = ?";				return $sqlStr;		}?>

... and site.php:

<?phpinclude "connection.php";include "site_queries.php";global $mysqli;?><?php$sql = getfrompages();if ($result = $mysqli->prepare($sql)){$rekza = 1;$result->bind_param("i",$rekza);$result->execute();	$result->store_result();$rowsZ = $result->num_rows;}if($rowsZ>0){$row = fetch($result);}echo $row["page_title"];?>

and all the files in the same folder....why my code doesnt work ? the echo ?

Edited by mekha
  • Like 1
Link to comment
Share on other sites

what is inside fetch()? var_dump() the $row to see what does it holds.

Link to comment
Share on other sites

what is inside fetch()? add it

$row = fetch($result);var_dump($row);

also make sure returned number of rows greater than 0.

Edited by birbal
Link to comment
Share on other sites

this is where i am showing my results:

<?phpinclude "includes/site_includes.php";?><?php$sql = getfrompages();if ($result = $mysqli->prepare($sql)){$rekza = (int)1;$result->bind_param("i",$rekza);$result->execute();$result->store_result();$rowsZ = $result->num_rows;}if($rowsZ>0){$row = fetch($result);}echo $row[0]["page_title"];echo $site_url;?>

this is the connection:

<?php$dbhost = 'localhost';$dbuser = 'xxx';$dbpass = 'zzzzz';$dbname = 'yyy';      $mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);/* check connection */if ($mysqli->connect_errno) {    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;	 }$mysqli->query("SET NAMES 'utf8' COLLATE 'utf8_general_ci'");?>

this the query:

<?phpfunction getfrompages(){  $sqlStr = "select * from tbl_pages where page_id = ?";  return $sqlStr;}?>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...