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?
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.
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: