10 Replies - 1231 Views - Last Post: 25 February 2010 - 04:44 AM

#1 happycamper   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 163
  • Joined: 11-November 08

Connecting to MYSQL with PHP

Posted 23 February 2010 - 12:40 PM

Here is the situation. I have the following test script set up on my server:

<?php
    
      @ $db = new mysqli('localhost', 'mydb', '********', 'customers');
      
      if (mysqli_connect_errno()) 
      {
        echo 'failure';
      }
      else
      {
        echo 'Success';
      }
    ?>


I have MYSQL downloaded on my computer. I have created a database, 'mydb' and have created some tables. I can connect to the database on my computer. How do I connect to the database from my server script?

Is This A Good Question/Topic? 0
  • +

Replies To: Connecting to MYSQL with PHP

#2 JackOfAllTrades   User is online

  • Saucy!
  • member icon

Reputation: 6248
  • View blog
  • Posts: 24,015
  • Joined: 23-August 08

Re: Connecting to MYSQL with PHP

Posted 23 February 2010 - 07:09 PM

This would seem to do it, but I've not used mysqli.
Was This Post Helpful? 0
  • +
  • -

#3 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6746
  • View blog
  • Posts: 31,222
  • Joined: 10-May 07

Re: Connecting to MYSQL with PHP

Posted 23 February 2010 - 07:11 PM

View Posthappycamper, on 23 February 2010 - 01:40 PM, said:

I have the following test script set up on my server:
...
I have MYSQL downloaded on my computer.

Are you trying to connect over the net, or are the terms computer & server interchangeable here?
Was This Post Helpful? 0
  • +
  • -

#4 happycamper   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 163
  • Joined: 11-November 08

Re: Connecting to MYSQL with PHP

Posted 23 February 2010 - 07:41 PM

When I say computer, I mean my physical laptop. When I say server I mean from my website.
Was This Post Helpful? 0
  • +
  • -

#5 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6746
  • View blog
  • Posts: 31,222
  • Joined: 10-May 07

Re: Connecting to MYSQL with PHP

Posted 23 February 2010 - 07:47 PM

So you want your website to load a database from your laptop? Is this correct?
Was This Post Helpful? 0
  • +
  • -

#6 happycamper   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 163
  • Joined: 11-November 08

Re: Connecting to MYSQL with PHP

Posted 23 February 2010 - 07:51 PM

I don't know. The book I'm using acts like all you do is type in the code and BAM, you're using PHP to send queries to and from the database.

Do I need to set up the database on the server first? Before I use PHP to access the database?

What I want to be able to do is have a MYSQL database and then have it interact with PHP on my website.

This post has been edited by happycamper: 23 February 2010 - 07:52 PM

Was This Post Helpful? 0
  • +
  • -

#7 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6746
  • View blog
  • Posts: 31,222
  • Joined: 10-May 07

Re: Connecting to MYSQL with PHP

Posted 23 February 2010 - 07:52 PM

Yes. A database must 1st exist before you can connect to it. Mainly because after you create the database, you grant user permissions for accessing, insert, changing, & dropping columns & tables from the database.
Was This Post Helpful? 0
  • +
  • -

#8 happycamper   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 163
  • Joined: 11-November 08

Re: Connecting to MYSQL with PHP

Posted 23 February 2010 - 08:03 PM

I have a database, it just exists on my laptop.
Was This Post Helpful? 0
  • +
  • -

#9 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6746
  • View blog
  • Posts: 31,222
  • Joined: 10-May 07

Re: Connecting to MYSQL with PHP

Posted 23 February 2010 - 08:05 PM

You'll have to upload it to the server. Assuming it's mysql, do you know how to perform an SQL dump?
Was This Post Helpful? 0
  • +
  • -

#10 happycamper   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 163
  • Joined: 11-November 08

Re: Connecting to MYSQL with PHP

Posted 23 February 2010 - 08:14 PM

SQL Dump.. I googled that and it looks that is probably what I am looking for.

The book I use doesn't cover that.. or I missed it.
Was This Post Helpful? 0
  • +
  • -

#11 Trogdor   User is offline

  • D.I.C Addict
  • member icon

Reputation: 15
  • View blog
  • Posts: 627
  • Joined: 06-October 06

Re: Connecting to MYSQL with PHP

Posted 25 February 2010 - 04:44 AM

You could also try to create the database, its tables and its first content from a PHP script on your server.
Or with a tool like phpmyadmin.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1