Using mysqli, but not sure if correct

I am trying ot swap things over to use the current php code, and am in the process on the page below, but it doesnt seem to be working, as there is no output.

http://www.orchardsciderandperry.com/New/


<?
$t=mysqli_query("select * from Testimonal order by test_ID desc");
while($g=mysqli_fetch_assoc($t)){ 
$testID = $g['test_ID'];
$testPic = mysql_real_escape_string($g['pic_Path']);
$testText = mysql_real_escape_string($g['text_Test']);
$testName = mysql_real_escape_string($g['name_Test']);
$fromTest = mysql_real_escape_string($g['from_Test']); 
?>

<div style="position:relative; border:#FFFFFF dotted 1px; width:920px; min-height:200px; float:left; margin-bottom:20px; padding:5px;">
<div style="position:relative; float:left; width:200px; height:200px;"><img src=".<?= $testPic ?>" width="200" height="200"></div>
<div style="position:relative; float:right; width:690px; height:auto; padding-right:10px; font-size:16px; padding-top:10px; line-height:22px;"><?= $testText ?></div>
<div style="position:relative; float:left; width:150px; height:15px; font-size:16px; line-height:22px; color:#F90; padding-top:10px; padding-left:20px;"><?= $testName ?> - <?= $fromTest ?></div>
</div>
<? } ?>

I been looking into it and I noticed I should add the resource identifier, so have added it like below:



<?
$t=mysqli_query($link, "select * from Testimonal order by test_ID desc");
while($g=mysqli_fetch_assoc($t)){ 
$testID = $g['test_ID'];
$testPic = $g['pic_Path'];
$testText = $g['text_Test'];
$testName = $g['name_Test'];
$fromTest = $g['from_Test']; 
?>

These are my resources.



<?php
 $db="x";
 $host="x";
 $user="x";
 $pass="x";
 $link=mysql_pconnect($host,$user,$pass);
 mysql_select_db($db); 
?>

These are stored as a include called config.php and being pulled onto the page as:

include(“config.php”);

You’re using mysql_connect and mysql_select_db, and then all of a sudden you switch to mysqli. That doesn’t work, since they are two completely disparate systems and you can’t just mix and match to your liking :slight_smile:

You should rewrite the connection to


<?php
 $db="x";
 $host="x";
 $user="x";
 $pass="x";
 $link=mysqli_connect('p:'.$host,$user,$pass,$db);
?>

(the p: before the host is to connect persistently, since there is no mysqli_pconnect function, see http://www.php.net/manual/en/mysqli.persistconns.php)

Hi Scallio,

Thanks for helping…

I added your change to get it as below:



<?php
 $db="x";
 $host="x";
 $user="x";
 $pass="x";
$link=mysqli_connect('p:'.$host,$user,$pass,$db);
 
?>


And it came back with this error.

Warning: mysqli_connect(): Persistent connections are disabled. Downgrading to normal in /content/sites/o/r/orchardsciderandperry.com/web/New/config.php on line 8

I have attached a link to the ini file below, and I’m wondering what i’m doing wrong in honesty as I started to use mysqli instead of mysql because the code wasnt working, so assumed it was because of that…

http://www.orchardsciderandperry.com/New/info.php

But by the looks the server isnt new enough is it to be using mysqli…

I’m using php that I have been using for ages, but it doesnt seem to want to work using either php way

It is installed, but it doesn’t allow for persistent connections. Remove the ‘p:’ from the code I posted earlier.

I thought that and tried it and although the error went I still couldnt get the data to display on the page, whilst all seems to be workign fine, this is what is confusing me.

This is the code as it stands now.

Thanks for coming back again.

config.php


<?php
 $db="x";
 $host="x";
 $user="x";
 $pass="x";
$link=mysqli_connect($host,$user,$pass,$db);
 ?>


index.php


<?php 
error_reporting(E_ALL);
ini_set('display_errors','On');
include("config.php");
?>

<?
$t=mysqli_query($link, "select * from Testimonal order by test_ID desc");
while($g=mysqli_fetch_assoc($t)){ 
$testID = $g['test_ID'];
$testPic = $g['pic_Path'];
$testText = $g['text_Test'];
$testName = $g['name_Test'];
$fromTest = $g['from_Test']; 
?>
<div style="position:relative; border:#FFFFFF dotted 1px; width:920px; min-height:200px; float:left; margin-bottom:20px; padding:5px;">
<div style="position:relative; float:left; width:200px; height:200px;"><img src=".<?= $testPic ?>" width="200" height="200"></div>
<div style="position:relative; float:right; width:690px; height:auto; padding-right:10px; font-size:16px; padding-top:10px; line-height:22px;"><?= $testText ?></div>
<div style="position:relative; float:left; width:150px; height:15px; font-size:16px; line-height:22px; color:#F90; padding-top:10px; padding-left:20px;"><?= $testName ?> - <?= $fromTest ?></div>
</div>
<? } ?>

http://www.orchardsciderandperry.com/New/

Can you please check the value of $t?
If it’s false, please you mysqli_error to find out what’s going wrong.
If everything seems fine, try a var_dump of $g to see what’s in there.

Hi,

I tried a var_dump on select and it came back with nothing, very strange, and used echo and var_dump as below and still nothing…


$t=mysqli_query($link,"SELECT * FROM Testimonal");
echo $t;
while($g=mysqli_fetch_assoc($t)){ 
var_dump($g);


I have double, triple checked the values in the config gile, and they are correct too, as I have broken the connection by changing the password or username and everytime I do that it comes back with an error, but when I put the correct details back the error goes away, so its connecting fine, just something not right.

I started a query with the host about this, and all they said was that php was enabled fine on the server, and this is the very first time anything like this has happened, and the code im using originally i have used over and over, pretty standard stuff really.

I have just noticed somethinng very strange, and obviously the problem.

When I view source, I can see the php.

So for some reason the php isnt being recognised on the page, but the include at the top of the page with the config file is fine and hidden in the view source…

http://www.orchardsciderandperry.com/New/

I changed <?

to

<?php and then got white out

crazy

Do not use short tags, e.g. <?
Always use full start tags <?php

I have seemed to have sorted the white out out, and wondered how you get around


<?= $testPic ?>

Because <?php = $testPic ?> doesnt work

Sorry guys I got it sorted now using <?php echo $testPic ?>

I’m jumping around so many languages these days that I sometimes forget the basics, thanks for all the help.

Out of curiosity, what are the other languages you’re programming in?

Although I never use it, when you have the = sign, e.g.

<?= $testPic ?>

it’s the same as

<?php echo $testPic ?>

(so I here)