473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Determining type of MySQL field.

I have a problem of migrating a database from one host to another.
I can't do a dump on the source server. The only access I have is thru
queries. So it looks like I'm going to have to query all the
tables and insert to the destination.

I'm trying to come up with a general solution to this problem which
uses queries to determine the structure of the source db, and create
the tables on the destination, which I've already done using the nice
"show create table" query syntax combined with the PHP
mysql_list_tables() function.

The problem comes with doing the inserts. It looks like I'm going to
have to do a "select * from table" thing and then loop thru the
recordset doing insert after insert.

Q: Do I have to do it that way? Is there a way I can insert all the
records from source to destination more efficiently?

Q: How can I determine the type of value in a field returned from
a query? PHP's is_string returns true on ALL fields regardless of type
used in the database itself. I need to know whether to wrap the values
in quotes or not before I insert them.

I'd like to be able to at least fetch a record and insert the record
without having to process it. I'd like to grab the whole table and
insert it, but haven't a clue how to do this.

Q: Is there some kind of select/fetch that I can do that will give me a
record ready to insert i.e. with commas and quotes?

TIA,

Jul 17 '05 #1
5 1918
gl***@potatoradio.f2s.com wrote:
I have a problem of migrating a database from one host to another.
I can't do a dump on the source server. The only access I have is thru
queries. So it looks like I'm going to have to query all the
tables and insert to the destination.

I'm trying to come up with a general solution to this problem which
uses queries to determine the structure of the source db, and create
the tables on the destination, which I've already done using the nice
"show create table" query syntax combined with the PHP
mysql_list_tables() function.

The problem comes with doing the inserts. It looks like I'm going to
have to do a "select * from table" thing and then loop thru the
recordset doing insert after insert.

Q: Do I have to do it that way? Is there a way I can insert all the
records from source to destination more efficiently?

Q: How can I determine the type of value in a field returned from
a query? PHP's is_string returns true on ALL fields regardless of type
used in the database itself. I need to know whether to wrap the values
in quotes or not before I insert them.

I'd like to be able to at least fetch a record and insert the record
without having to process it. I'd like to grab the whole table and
insert it, but haven't a clue how to do this.

Q: Is there some kind of select/fetch that I can do that will give me a
record ready to insert i.e. with commas and quotes?

TIA,


The following queries will return the info you need:

SHOW TABLES // returns list of tables
DESCRIBE <table name> // returns column name, type, options, etc...

NM

--
convert UPPERCASE NUMBER to a numeral to reply
Jul 17 '05 #2
May be if you try to use some PL/SQL script it will be easier, but
don't know how!!!
You can ask some Database experts for idea's and then get back to ask
about ways to convert these idea's to PHP script..

Jul 17 '05 #3

News Me wrote:

The following queries will return the info you need:

SHOW TABLES // returns list of tables
PHP's mysql_list_tables is more useful, because the result doesn't
need to be processed.
DESCRIBE <table name> // returns column name, type, options, etc...


MySQL's 'SHOW CREATE TABLE' returns a string that can be used to
duplicate the table on the other host.

Also, I made the mistake of assuming that MySQL was strongly typed,
i.e. that strings had to be quoted, but scalers could not be. It
turned out that if you quote everything, it works fine (but you
have to addslashes() to the string you create.

The problem now is that I have auto_increment fields. ... oooooh.

Jul 17 '05 #4
<gl***@potatoradio.f2s.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com...

News Me wrote:

The following queries will return the info you need:

SHOW TABLES // returns list of tables


PHP's mysql_list_tables is more useful, because the result doesn't
need to be processed.
DESCRIBE <table name> // returns column name, type, options, etc...


MySQL's 'SHOW CREATE TABLE' returns a string that can be used to
duplicate the table on the other host.

Also, I made the mistake of assuming that MySQL was strongly typed,
i.e. that strings had to be quoted, but scalers could not be. It
turned out that if you quote everything, it works fine (but you
have to addslashes() to the string you create.

The problem now is that I have auto_increment fields. ... oooooh.

I have recently (like on Friday) completed a script to "backup" a mySQL
database from one server to another. It does this by first obtaining the
structure of the source DB and recreating that structure in the destination
(the DB must not exist on the destination host - it creates the DB then
inserts the tables). Then it cycles through the source DB, one table at a
time and one field at a time - pulls a field form the source, then writes
it to the destination. In short, it's an automated means to totally
duplicate a DB. So far, It's worked on tables with 10,000+ records and sizes
of 100M+.

If it seems like something that could help, email me at "tony" at
"naturesflavors" dot "com" and I'll send you the code.
Jul 17 '05 #5
"Gordon Burditt" <go***********@burditt.org> wrote in message
news:42**********************@news.airnews.net...
I'm trying to come up with a general solution to this problem which
uses queries to determine the structure of the source db, and create
the tables on the destination, which I've already done using the nice
"show create table" query syntax combined with the PHP
mysql_list_tables() function.

The problem comes with doing the inserts. It looks like I'm going to
have to do a "select * from table" thing and then loop thru the
recordset doing insert after insert.
MySQL allows an extended insert statement which inserts a whole bunch
of records at a time. The queries generated by mysqldump -opt can
get ridiculously long (breaks my editor) like 50k per line.


I have been unable to import most of my databases using mysqldump because
they're too big. I'm getting dump files of 100MB or so. phpmyadmin doesn't
process them (it doesn't even try), and when I try to insert via a command
line, it parses a portion of them then craps out on an error.

The mysql_field_* and mysql_list_fields functions might help.
I'd like to be able to at least fetch a record and insert the record
without having to process it. I'd like to grab the whole table and
insert it, but haven't a clue how to do this.

Q: Is there some kind of select/fetch that I can do that will give me a
record ready to insert i.e. with commas and quotes?
I have used queries that look like:

select concat('INSERT INTO foobar VALUES (\'', variable1, '\', \'', ....

, ) from foobar2 ;

but mostly where I already know the structure of the table. This is probably what mysqldump does, though.


When I looked at my mysqldump files, it had a series of statements to create
the tables, then an INSERT statement for each record:

INSERT INTO foobar VALUES ('var1', 'var2', ... );

Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Yulia Yegenov | last post by:
I have a query that looks like this: (I insert the date created with the php date function) $status = "Active"; //(I cannot use the mysql timestamp function for other reason). $curdate =...
3
by: kingofkolt | last post by:
All, What do you recommend as the best type of field for a timestamp in a MySQL database? I've considered varchar(10) or INT but I'm not sure what is the best, most efficient, and most reliable...
2
by: Iaiken | last post by:
I am using vb.net and the myoledb provider. I've run into a problem where what I need to do is open a database connection to a mysql server, easy. The problem arrises in that I want to, if...
0
by: jnam | last post by:
I am having a problem putting a certain length of text from a textarea form element into a mySQL field. The field is set to LONGTEXT but I get an error. Whne I shorten the text it writes to the DB...
1
by: Henry Stockbridge | last post by:
I am doing some database documentation, and need to convert the field type and field formats in my code into terms I can convey to others (i.e. Date/Short Date, Number/Double, and so forth.) Any...
2
by: Laszlo Szijarto | last post by:
Using reflection, I am iterating through an array of FieldInfo objects and wish to determine whether any given field represents a signed or an unsigned variable (makes a difference in terms of how...
3
by: bobmct | last post by:
In my feeble attempt to keep track of login session timeouts I have the following code in my login section of my program: $sql = "UPDATE subscriber SET _sessexp = 'DATE_ADD(NOW(),INTERVAL 15...
2
by: daknightuk | last post by:
I have created a database and I want to add a field to it which will store the password using the php encryption method of MD5 or SHA1 I just simply need to know what datatype to use in the...
2
by: jewellman | last post by:
Hello. I have been reading over some posts that deal with my issue and although I couldn't get my issue to work I did read some very good information. I have created a mySQL table that I will use...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.