PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
mekha
Forum Contributor
Posts: 112 Joined: Sat Mar 31, 2012 6:50 am
Post
by mekha » Sun Sep 02, 2012 12:48 pm
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 ?
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Sun Sep 02, 2012 10:23 pm
Try checking $mysqli->connect_errno istead of mysqli_connect_errno().
(#10850)
mekha
Forum Contributor
Posts: 112 Joined: Sat Mar 31, 2012 6:50 am
Post
by mekha » Mon Sep 03, 2012 12:18 am
nope:S without results :S
social_experiment
DevNet Master
Posts: 2793 Joined: Sun Feb 15, 2009 11:08 am
Location: .za
Post
by social_experiment » Mon Sep 03, 2012 12:41 am
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();
?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
mekha
Forum Contributor
Posts: 112 Joined: Sat Mar 31, 2012 6:50 am
Post
by mekha » Mon Sep 03, 2012 2:11 am
still not working :\
social_experiment
DevNet Master
Posts: 2793 Joined: Sun Feb 15, 2009 11:08 am
Location: .za
Post
by social_experiment » Mon Sep 03, 2012 5:20 am
are you receiving any error messages?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
mekha
Forum Contributor
Posts: 112 Joined: Sat Mar 31, 2012 6:50 am
Post
by mekha » Mon Sep 03, 2012 8:40 am
no :S
social_experiment
DevNet Master
Posts: 2793 Joined: Sun Feb 15, 2009 11:08 am
Location: .za
Post
by social_experiment » Mon Sep 03, 2012 8:47 am
Even if you use the snippet of code from the php manual?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
mekha
Forum Contributor
Posts: 112 Joined: Sat Mar 31, 2012 6:50 am
Post
by mekha » Mon Sep 03, 2012 12:20 pm
i dont know whats going on!...
the $sql is undefined...the query....even that i included all the files :\
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Mon Sep 03, 2012 11:00 pm
mekha wrote: the $sql is undefined...the query....even that i included all the files :\
What does getfrompages() return?
(#10850)
mekha
Forum Contributor
Posts: 112 Joined: Sat Mar 31, 2012 6:50 am
Post
by mekha » Tue Sep 04, 2012 12:17 am
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!
mekha
Forum Contributor
Posts: 112 Joined: Sat Mar 31, 2012 6:50 am
Post
by mekha » Tue Sep 04, 2012 3:26 am
ok thanks...i succeed thnk you every one