Using PHP, I have a sql file which I want to import into my database.
Unfortunately, I can't use any command (php exec).
How can I do that (without phpMyAdmin and co) ?
Thanks.
Or with PHP only.
Please note the SQL file should include USE database statement(s) because mysqli_connect doesn't use a default database.
SQL file code
USE stackoverflow;
CREATE TABLE test() (
id int
);
PHP code
<?php
$fileContentsString = file_get_contents([path_to_sql_file]);
$connection = mysqli_connect("127.0.0.1", "username", "password");
mysqli_multi_query($connection, $fileContentsString);
?>
Better use MySQL Workbench. MySQL Workbench is a visual database design tool that integrates SQL development, administration, database design, creation and maintenance into a single integrated development environment for the MySQL database system
if you have access to phpMyAdmin, then you should be able to create a database
create database
using the xampp or wampp GUI, select the newly created database and then click import import and then select the sql file select sql file you want to upload and click go click go to complete process at the bottom, it should then bring a message Import successful.... after the entire process, you are good to go
Related
I have a problem when importing a table form SQL Server to MySQL.
This is what I do:
First I export a CSV file with the data of the table Clients from SQL Server.
Then I import that CSV file to an auxiliar table in MySQL.
Finaly, I execute a query to insert the new data into the Clients table from MySQL
Is there any way to automatize this process? I've tried several methods, but it wasn't successful. ( Methods such as link both servers and configure them. )
English is not my first language.
Kind regards.
You should be able to create a linked server between them and execute your insert directly into MySQL. Take this code once working and put it into a scheduled job.
MySQL Linked Server Set Up
Hey guys the code below is what I am trying to run. I am trying to run a practice MySQL server because I am going to host it on my schools free database which is MySQL
I am using phpmyADMIN but I am a bit confused because yall are saying I am not connecting to MySQL
so what is this code to create a database? Do I need to download MySQL or something? I thought phpmyadmin is the same syntax to create a database/tables/ and values? since I have MySQL turned on?
//creation of database
$sql= 'CREATE DATABASE project';
if(mysql_query($sql,$con)){
echo 'DB created succesfully';
}
else{
echo 'error creating DB' . mysql_errno();
}
PHPMyAdmin is a web-based software program created with PHP to help you administrate MySQL databases. It has its own internally built code to connect to your MySQL databases and perform standard functions such as insert, select, delete, update, etc.
PHPMyAdmin does not really have anything to do with you creating your own PHP program. You will still need to connect to MySQL (as PHPMyAdmin does behind the scenes). You can still use the same code that PHPMyAdmin generates for you for use in your own PHP programs, but you must already be connected to MySQL as a user with valid permissions.
In your PHP code it is important to note that you are using the mysql_* functions which have been deprecated and you should be using the mysqli_* functions instead.
Your code should actually look something like this:
//connect to db
$link = mysqli_connect("localhost","my_user","my_password");
//creation of database
$sql= 'CREATE DATABASE project';
if(mysqli_query($link, $sql)){
echo 'DB created succesfully';
}
else{
echo 'error creating DB' . mysqli_errno();
}
MySQL is the database server you connect to in order to execute queries such as CREATE DATABASE project. phpmyadmin is a PHP-based front end to MySQL to allow easier browsing and manipulation of the database.
Think of text documents on your computer. notes.txt is a text file, but you could open it with any text editor such as Notepad or TextEdit.
Your specific snippet of code is missing the database connection string, so something more appropriate might look like:
$connection = new mysqli('db_host', 'db_user', 'db_pass');
$sql = "CREATE DATABASE project";
$results = mysqli_query($connection, $sql);
//check for errors
Without connecting to the database, your SQL is all just strings of text with no meaning.
I tried a lot hoping to get a good job here
If you are logged into phpmyadmin, then the only code you can execute is just SQL statements. Like: create database my_db1
I'm relatively new to PHP and databases. Currently I'm working with an existing Access database and am able to read and display the data just fine. However, I'm wanting to update a user record through an email verification link. I have the server send an email with a link of www.domain.com/verify.php?userID=#
I am able to read this GET variable just fine, but I'm completely lost as to how I update the record. Everything I search for is for updating MySQL databases whereas I'm using odbc.
Does anyone know how I could set this up?
something like this:
odbc_exec($conn, "UPDATE table SET field=value"); // $conn is your connection identifier
You need to use a ODBC database client library in PHP to connect to a ODBC datasource. For example you can use PDO with the driver ODBC and DB2 Functions (PDO_ODBC).
I'm creating locally a big database using MySQL and PHPmyAdmin. I'm constantly adding a lot of info to the database. I have right now more than 10MB of data and I want to export the database to the server but I have a 10MB file size limit in the Import section of PHPmyAdmin of my web host.
So, first question is how I can split the data or something like that to be able to import?
BUT, because I'm constantly adding new data locally, I also need to export the new data to the web host database.
So second question is: How to update the database if the new data added is in between all the 'old/already uploaded' data?
Don't use phpMyAdmin to import large files. You'll be way better off using the mysql CLI to import a dump of your DB. Importing is very easy, transfer the SQL file to the server and afterwards execute the following on the server (you can launch this command from a PHP script using shell_exec or system if needed) mysql --user=user --password=password database < database_dump.sql. Of course the database has to exist, and the user you provide should have the necessary privilege(s) to update the database.
As for syncing changes : that can be very difficult, and depends on a lot of factors. Are you the only party providing new information or are others adding new records as well? Are you going modify the table structure over time as well?
If you're the only one adding data, and the table structure doesn't vary then you could use a boolean flag or a timestamp to determine the records that need to be transferred. Based on that field you could create partial dumps with phpMyAdmin (by writing a SQL command and clicking Export at the bottom, making sure you only export the data) and import these as described above.
BTW You could also look into setting up a master-slave scenario with MySQL, where your data is transferred automatically to the other server (just another option, which might be better depending on your specific needs). For more information, refer to the Replication chapter in the MySQL manual.
What I would do, in 3 steps:
Step 1:
Export your db structure, without content. This is easy to manage on the exporting page of phpmyadmin. After that, I'd instert that into the new db.
Step 2:
Add a new BOOL column in your local db in every table. The function of this is, to store if a data is new, or even not. Because of this set the default to true
Step 3:
Create a php script witch connects to both databases. The script needs to get the data from your local database, and put it into the new one.
I would do this with following mysql methods http://dev.mysql.com/doc/refman/5.0/en/show-tables.html, http://dev.mysql.com/doc/refman/5.0/en/describe.html, select, update and insert
then you have to run your script everytime you want to sync your local pc with the server.
I'm working on a project atm, and I need to import data that is stored in a MS ACCESS database to mySql. For mySql I'm using phpMyAdmin on a Ubuntu machine, I have another Windows Machine where I can access the Access DB from, In MS Access 2003 I can't find an option to convert the data to mySql? Can this be done?
Take a look at Access to MySQL. Makes it easy to convert an Access database to MySQL.
It's always possible to do a quick and dirty export from Access to any ODBC database by selecting a table in Access and simply choosing EXPORT from the File menu. One of the export options (in the dropdown at the bottom) is ODBC, and if you have a DSN set up for your other database, you can export directly. Obviously, the data types won't necessarily be perfect for the target database, but it won't misconvert any data -- you just may need to tighten up the data types after the export.
I think it's astonishing that Access can do this, to be honest, but it works.
step by step guide to running Access frontend application with MySQL database on webserver (you dont need to IMPORT the tables, you can use your msaccess application WITH them on the webserver) and EXPORTING MsAccess tables to MySQL (once you start down that path, you want it to be a two-way road, believe me):
If you are running MsAccess, i suppose that you are using windows
Install MySQL ODBC 5.1 Driver (connector) http://dev.mysql.com/downloads/connector/odbc/
Open CONTROL PANEL on win machine
ADMINISTRATIVE TOOLS (if Vista or Seven, search ODBC)
SET UP DATA SOURCES ODBC
SYSTEM DSN
ADD
depending on your server, you might have some difficulty finding the server name or IP, look for SSH Database connection (or something like that). as an example, read NetSol's FAQ: http://www.networksolutions.com/support/how-to-back-up-the-mysql-database-using-ssh/
if you want to BATCH EXPORT / DUMP to MySQL from MsAccess, you can create a FORM in access, put a button on it, and in VBA create this sub for the OnClick() event:
Dim sTblNm As String
Dim sTypExprt As String
Dim sCnxnStr As String, vStTime As Variant
Dim db As Database, tbldef As DAO.TableDef
On Error GoTo ExportTbls_Error
sTypExprt = "ODBC Database"
sCnxnStr = "ODBC;DSN=DSNname;UID=userOnServer;PWD=pwdOnServer"
vStTime = Timer
Application.Echo False, "Visual Basic code is executing."
Set db = CurrentDb()
For Each tbldef In db.TableDefs
Debug.Print tbldef.Name
sTblNm = tbldef.Name
DoCmd.TransferDatabase acExport, sTypExprt, sCnxnStr, acTable, sTblNm, sTblNm
Next tbldef
MsgBox "Done!"
On Error GoTo 0
SmoothExit_ExportTbls:
Set db = Nothing
Application.Echo True
Exit Sub
ExportTbls_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure ExportTblsODST"
Resume SmoothExit_ExportTbls
sometimes, while running non-english windows you might get error 2507. change "ODBC Database" for "ODBC" (works with French).
IMPORTING: in MsAccess:
1. FILES
2. EXTERNAL DATA SOURCE
3. LINK TABLES
an MsAccess frontend doesnt really care what database engine it is using, so safe practice is to have 2 separate MDB's: queries, forms, macros, etc AND raw data. that way, you can seamlessly switch from using local database to remote server. and your core application file doesnt contain data proper.