0

Im thinking this isn't an exact duplicate of the other question because i "am not trying to mix api's". I do not want to anyway. My db host provider told me to change the code because i could not get this first code to connect till i changed it to what they say. Perhaps since I changed that, I have to change the rest of the code to match or because i left the code the same "i am mixing api's"? Im so confused.

This is the code i use on my local host and my entire php file (with html) works fine.

    <?php
$dbHost = 'localhost';
$dbUsername = 'root';
$dbPassword = '';
$dbName = 'example';

$db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);

if ($db->connect_error) {
    die("Unable to connect database: " . $db->connect_error);
} 

?>

When on my server i had to change it to this in order for it to connect properly.

    <?php
$dbHost = 'user.ipowermysql.com';
$dbUsername = '';
$dbPassword = '';
$dbName = '';

$db = mysql_connect($dbHost, $dbUsername, $dbPassword);

mysql_select_db($dbName, $db);

if ($db->connect_error) {
    die("Unable to connect database: " . $db->connect_error);
} 

?>

I got that part figured out. I asked power and they said i can't use mysql i and have to use mysql. I don't understand why but it works.

Now when I try to call to get info onto my webpage using this code below, I get an error. Everything on the webpage above the php call shows up but everything on the webpage after the php code is somehow gone and of course the code doesn't work. Here is the code I'm using on the page to call. This works fine on localhost and shows the full webpage and gets the info I'm calling but not on server. Im completely new to php and was happy to get it finally working on my localhost. Now I'm loosing it trying to figure it out on the server

    <?php


        $query = $db->query("SELECT * FROM slideshow ORDER by ID ASC");
        if($query->num_rows > 0){ 
            while($row = $query->fetch_assoc()){
        ?>

<img src="<?php echo $row["image"]; ?>"/>

 <?php } } ?> 

Here is the error i get: PHP Fatal error: Call to a member function query() on a non-object.

  • 1
    because you're mixing apis maybe? – Funk Forty Niner Jan 09 '17 at 22:04
  • 3
    Frankly, if they say you have to use mysql_ instead of mysqli or PDO, I'd run away as fast as I could. – aynber Jan 09 '17 at 22:05
  • 1
    Honestly, I'm surprised that you can connect at all with the information that your db host gave you. I'd go with @aynber in this one - if they say you have to use mysql instead of mysqli or PDO, this might be a good time to run away!! – 0708 Jan 09 '17 at 22:07
  • @aynber I just went into chat with them and now they say i CAN use mysql i. sigh... now i don't know why then that the first code didnt work then. – LAUREN HALL Jan 09 '17 at 23:00
  • The host company contacted me and it turns out this whole 2 day process was a problem with the host company and the code was right all along. after they sent me a message i went back to the original code and all was working. great but it made me waste two days of my life pulling out my hair. thank you all for trying to help and sorry i had to post this to try to get help!! – LAUREN HALL Jan 10 '17 at 01:41

0 Answers0