Jump to content
xisto Community
Sign in to follow this  
iGuest

How To Execute sql file to create table

Recommended Posts

In php/mysql i want to create 10 tables and add data to each one, but the file size is still small enough...
I'm incorporating this into a broswer based upload/backup script without using cpanel.... in php

Can i just put

$query = "

all of the sql info - for multiple tables and insertion and updation

";

$result = mysql_query($query);  

in one file.

Will $result process all the queries if they are only defined as one big query? - or do i need to set it for each command


Oooo-that's a tough one! :) For that, we go to the PHP manual and their wonderful function reference!

It turns out that you cannot execute more than one MySQL query in one mysql_query() function call. However, browsing the notes for the mysql_query function on their website reveals that someone made a function for running multiple queries:
//$q is the query string ($thesql returned string)//$link is the link to the database connection//returns true or false depending on whether a single query is executed allows you to check to see if any queries were ranfunction multiple_query($q,$link) {   $tok = strtok($q, ";n");   while ($tok) {       $results=mysql_query("$tok",$link);       $tok = strtok(";n");   }   return $results;}

Okay. I'm going to have to explain a couple of things. First, The variables. As it says in the comments, $q is the query (containing multiple queries) you want to run. $link is the link returned by the mysql_connect function.

You're going to have to change your big query. After each individual query, you need to add a ';'. This is because the function tokenizes (separates) the query using these.

If this doesn't work, or if you have more questions, just post again.

Share this post


Link to post
Share on other sites
i need to syncronise between my local host and online data base How To Execute sql file to create table

hello every one

I need a php code that can read the data from my localhost data base on phpMyAdmin and make connect to the online data base and write the data there .. Any one can help please

thank every one 

-reply by ahmed

Share this post


Link to post
Share on other sites
please help me php nukeHow To Execute sql file to create table

This is the first time I have tried to get a website up and running and unfortunately I have people counting on me to make it happen (unlikely) lol...Ok so when I try to login as an admin it doesn't do anything...Just stays there...Also do I need to create a database? I don't understand coding or what to do...Basically I would just really like access to my php admin panel? can you please help I have been killing myself with non stop computer time and getting nowhere.

-reply by khris

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.