0

In my Google Drive Storrage I have a database (SQL file) which I want to read out from a PHP file on my webserver. The database looks like this:

DB_Name:  Test
TBL_Name: Namen

| id | Vorname |  Nachname  |
-----------------------------
|  1 | Max     | Mustermann |
|  2 | Hanz    | Peter      |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Now I tried to connect to the SQL file with this basic PHP code:

$verbindung = mysql_connect($driveLink, "", "")
or die("Failed to create connection.");

mysql_select_db("Test")
or die ("The database does not exists.");

$abfrage = "SELECT Vorname FROM Namen";
$ergebnis = mysql_query($abfrage);

while($row = mysql_fetch_object($ergebnis))
{
    echo "$row->Vorname";
}

But I can't get a connection to the file. Why is that? I have not set a username or password for the database so I pass empty strings to it, right? Also I gave the file access to everyone so I can reach the file from my code.

Is that because there is no underlying system like PhpMyAdmin or something else? How can I connect to the database from PHP?

Cilenco
  • 6,951
  • 17
  • 72
  • 152
  • You could perhaps use sqlite in your google drive storage - and use the sqlite functions of PHP. But to use a MySQL server you need a MySQL server up and running to connect to. That's a bit more than having just one file. – VMai Aug 06 '14 at 14:53

2 Answers2

2

An SQL file only contains raw SQL commands, which you can run on a database server.

When you use mysql_connect, you have to connect to a database server (specifically a MySQL database server). Then you can use other SQL commands via mysql_query.

Is that because there is no underlying system

Yes

like PhpMyAdmin

No. PHPMyAdmin is an SQL client, not a server. It also has to connect to a MySQL server.


NB: mysql_ is an obsolete database API and should use a modern replacement.

Community
  • 1
  • 1
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

this is inpossible because php cannot 'read' the sql-File so you have to make a online Databse

there are some free services for that:

my hostpoint

YvesHendseth
  • 1,149
  • 1
  • 10
  • 27