Page 1 of 1

why i cant connect to mysqli?

Posted: Sun Sep 02, 2012 12:48 pm
by mekha
i have this connection:

Code: Select all

<?php
DEFINE('DATABASE_USER', 'xxxxxxxx');
DEFINE('DATABASE_PASSWORD', 'xxxxxxxx');
DEFINE('DATABASE_HOST', 'localhost');
DEFINE('DATABASE_NAME', 'xxxxxxx');
$mysqli = new mysqli(DATABASE_HOST, DATABASE_USER, DATABASE_PASSWORD, DATABASE_NAME);
if (mysqli_connect_errno()) {
	printf("Connect failed: %s\n", mysqli_connect_error());
	exit();
}
	else {
	//connected	
}
?>
...and site_queries.php:

Code: Select all

<?php
	function getfrompages()
	{
		$sqlStr = "select * from tbl_pages where page_id = ?";
		return $sqlStr;
	}
?>
... and site.php:

Code: Select all

<?php
include "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 ?

Re: why i cant connect to mysqli?

Posted: Sun Sep 02, 2012 10:23 pm
by Christopher
Try checking $mysqli->connect_errno istead of mysqli_connect_errno().

Re: why i cant connect to mysqli?

Posted: Mon Sep 03, 2012 12:18 am
by mekha
nope:S without results :S

Re: why i cant connect to mysqli?

Posted: Mon Sep 03, 2012 12:41 am
by social_experiment
A sample from the PHP Manual that might be useful to you :)

Code: Select all

<?php
$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'my_db');

/*
 * This is the "official" OO way to do it,
 * BUT $connect_error was broken until PHP 5.2.9 and 5.3.0.
 */
if ($mysqli->connect_error) {
    die('Connect Error (' . $mysqli->connect_errno . ') '
            . $mysqli->connect_error);
}

/*
 * Use this instead of $connect_error if you need to ensure
 * compatibility with PHP versions prior to 5.2.9 and 5.3.0.
 */
if (mysqli_connect_error()) {
    die('Connect Error (' . mysqli_connect_errno() . ') '
            . mysqli_connect_error());
}

echo 'Success... ' . $mysqli->host_info . "\n";

$mysqli->close();
?> 

Re: why i cant connect to mysqli?

Posted: Mon Sep 03, 2012 2:11 am
by mekha
still not working :\

Re: why i cant connect to mysqli?

Posted: Mon Sep 03, 2012 5:20 am
by social_experiment
are you receiving any error messages?

Re: why i cant connect to mysqli?

Posted: Mon Sep 03, 2012 8:40 am
by mekha
no :S

Re: why i cant connect to mysqli?

Posted: Mon Sep 03, 2012 8:47 am
by social_experiment
:dubious: Even if you use the snippet of code from the php manual?

Re: why i cant connect to mysqli?

Posted: Mon Sep 03, 2012 12:20 pm
by mekha
i dont know whats going on!...

the $sql is undefined...the query....even that i included all the files :\

Re: why i cant connect to mysqli?

Posted: Mon Sep 03, 2012 11:00 pm
by Christopher
mekha wrote:the $sql is undefined...the query....even that i included all the files :\
What does getfrompages() return?

Re: why i cant connect to mysqli?

Posted: Tue Sep 04, 2012 12:17 am
by mekha
i solved some!...

the problem is here:

if($rowsZ>0)
{
$row = fetch($result);
$title = $row[0]["page_title"];
}

echo $title;

if i echo $rowsZ i get 1 ...thats mean there is results...but the echo dont work!

Re: why i cant connect to mysqli?

Posted: Tue Sep 04, 2012 3:26 am
by mekha
ok thanks...i succeed :D thnk you every one