Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. MYSQL connect through PHP

MYSQL connect through PHP

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
phpdatabasemysqlsysadminhosting
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    offroaderdan
    wrote on last edited by
    #1

    Hi, I have an email through my web hosting service which has told me my database details. they go MySQL Hostname: 99.99.999.999 MySQL Username: xxx xxx MySQL Passwor: aaaaahh MySQL Server: MySQL 1 I was able to connect to a differnet database which did not have mysql server on it by using the following code $hostname = "99.99.999.999"; $password = "aaaaahh"; $username = "xxx xxx"; Now i thought that this was simply going to be adding a $server variable on underneath so the complete code would look like this $hostname = "99.99.999.999"; $password = "aaaaahh"; $username = "xxx xxx"; $server = "MySQL 1"; $connection = mysql_pconnect($hostname, $server, $username, $password); if (!$connection) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_close($connection) ?> However this doesn't seem to do anything? Any help would be great Many Thanks Dan

    G S R 3 Replies Last reply
    0
    • O offroaderdan

      Hi, I have an email through my web hosting service which has told me my database details. they go MySQL Hostname: 99.99.999.999 MySQL Username: xxx xxx MySQL Passwor: aaaaahh MySQL Server: MySQL 1 I was able to connect to a differnet database which did not have mysql server on it by using the following code $hostname = "99.99.999.999"; $password = "aaaaahh"; $username = "xxx xxx"; Now i thought that this was simply going to be adding a $server variable on underneath so the complete code would look like this $hostname = "99.99.999.999"; $password = "aaaaahh"; $username = "xxx xxx"; $server = "MySQL 1"; $connection = mysql_pconnect($hostname, $server, $username, $password); if (!$connection) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_close($connection) ?> However this doesn't seem to do anything? Any help would be great Many Thanks Dan

      G Offline
      G Offline
      Graham Breach
      wrote on last edited by
      #2

      Server and hostname usually mean the same thing - the address of the server. In any case, you have the arguments to mysql_pconnect[^] wrong, it should be:

      $connection = mysql_pconnect($hostname, $username, $password);

      This is assuming the server name is in the $hostname variable. I suspect $server is actually the database name, so you should select this after connection using mysql_select_db[^].

      if(!mysql_select_db($server, $connection)) { ...

      1 Reply Last reply
      0
      • O offroaderdan

        Hi, I have an email through my web hosting service which has told me my database details. they go MySQL Hostname: 99.99.999.999 MySQL Username: xxx xxx MySQL Passwor: aaaaahh MySQL Server: MySQL 1 I was able to connect to a differnet database which did not have mysql server on it by using the following code $hostname = "99.99.999.999"; $password = "aaaaahh"; $username = "xxx xxx"; Now i thought that this was simply going to be adding a $server variable on underneath so the complete code would look like this $hostname = "99.99.999.999"; $password = "aaaaahh"; $username = "xxx xxx"; $server = "MySQL 1"; $connection = mysql_pconnect($hostname, $server, $username, $password); if (!$connection) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_close($connection) ?> However this doesn't seem to do anything? Any help would be great Many Thanks Dan

        S Offline
        S Offline
        Shamit Kumar Tomar
        wrote on last edited by
        #3

        Hi, You are doing it wrong. The correct syntax of mysql_pconnect is:

        $connection = mysql_pconnect($server, $username, $password, $client_flags);

        So, if you have the hostname, you must use it instead of using ServerName. So, all you have to do is use this piece of code:

        $hostname = "99.99.999.999";
        $password = "aaaaahh";
        $username = "xxx xxx";
        $server = "MySQL 1";

        $connection = mysql_pconnect($hostname, $username, $password);

        if (!$connection)
        {
        die('Could not connect: ' . mysql_error());
        }

        echo 'Connected successfully';
        mysql_close($connection);

        See, I have not used $server anywhere. Not needed. Give it a try. Enjoy.

        Procrastination and Improvisation are my two swords to fight life. My Portfolio Website

        1 Reply Last reply
        0
        • O offroaderdan

          Hi, I have an email through my web hosting service which has told me my database details. they go MySQL Hostname: 99.99.999.999 MySQL Username: xxx xxx MySQL Passwor: aaaaahh MySQL Server: MySQL 1 I was able to connect to a differnet database which did not have mysql server on it by using the following code $hostname = "99.99.999.999"; $password = "aaaaahh"; $username = "xxx xxx"; Now i thought that this was simply going to be adding a $server variable on underneath so the complete code would look like this $hostname = "99.99.999.999"; $password = "aaaaahh"; $username = "xxx xxx"; $server = "MySQL 1"; $connection = mysql_pconnect($hostname, $server, $username, $password); if (!$connection) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_close($connection) ?> However this doesn't seem to do anything? Any help would be great Many Thanks Dan

          R Offline
          R Offline
          Rockyonfire
          wrote on last edited by
          #4

          Server isnt a accepted value in the connection string.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups