0

i used the following code to create a table table is created but warning is shown

No index defined!

i used the following SQL command to create table

CREATE TABLE IF NOT EXISTS `test` (
`path` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1; 

i used the following PHP code to insert multiple image path into database but each path is store in new row how do i store in single row in SQL table

if ($_FILES) {
$upload = new Upload_Rename();
$destination = 'upload';
$paths=$upload->multiple_files($_FILES['myfile'], $destination);

//Fill this with correct information
$mysql_hostname = "";
$mysql_user = "";
$mysql_password = "";
$mysql_database = "";
$tbl_name="";
$pathfield_name='path';
//
$mysql= new mysqli($mysql_hostname,$mysql_user,$mysql_password,$mysql_database);
foreach($paths as $path){
$query='INSERT INTO `'.$tbl_name.'` (id, `'.$pathfield_name.'`) VALUES ("'.$mysql- >escape_string($path).'");';
$mysql->query($query);}
$mysql->close();
}
?>

<form  method="post" enctype="multipart/form-data">
<?php for ($i = 0; $i < 10; $i++): ?>
file: <input type="file" name="myfile[]"><br>
<?php endfor; ?>
 <input type="submit">
5
  • how to create index in that Commented Jul 22, 2014 at 9:45
  • I don't see anything wrong with that. Mind showing us the rest of the contents inside the db? Commented Jul 22, 2014 at 9:45
  • As you wrote that is only a warning not an error. It only says you that you have not specified an index. Commented Jul 22, 2014 at 9:46
  • 1
    @user3853978 See mysql doc Commented Jul 22, 2014 at 9:47
  • You're inserting (id, path) into a table that has only path column - that's what your code says. Commented Jul 22, 2014 at 9:55

3 Answers 3

1
  1. If you define a PRIMARY KEY on your table, InnoDB uses it as the clustered index.

  2. If you do not define a PRIMARY KEY for your table, MySQL picks the first UNIQUE index that has only NOT NULL columns as the primary key and InnoDB uses it as the clustered index.

  3. If the table has no PRIMARY KEY or suitable UNIQUE index, InnoDB internally generates a hidden clustered index on a synthetic column containing row ID values. The rows are ordered by the ID that InnoDB assigns to the rows in such a table. The row ID is a 6-byte field that increases monotonically as new rows are inserted. Thus, the rows ordered by the row ID are physically in insertion order.

So in case of 3 the synthetic index will be created. And this warning just provides the understanding, that no special index has been defined for the table, that can cause in the future issues with sorting, searching e.t.c. queries.

http://dev.mysql.com/doc/refman/5.0/en/innodb-index-types.html

Sign up to request clarification or add additional context in comments.

Comments

0

You should have a PK as A_I field in your table, thats better performance for query/indexing.

CREATE TABLE IF NOT EXISTS `test` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`path` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Also, the path only 50 chars, why you expected multiple paths in 1 row? What is purpose?

2 Comments

SQL query: CREATE TABLE IF NOT EXISTS test1 ( id INT UNSIGNED NOT NULL AUTO_INCREMENT , path VARCHAR( 50 ) NOT NULL ) ENGINE = INNODB DEFAULT CHARSET = latin1 MySQL said: Documentation #1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key
Please add PRIMARY KEY (id) to it. Like this: CREATE TABLE IF NOT EXISTS test1 ( id INT UNSIGNED NOT NULL AUTO_INCREMENT , path VARCHAR( 50 ) NOT NULL, PRIMARY KEY (id) ) ENGINE = INNODB DEFAULT CHARSET = latin1;
0
CREATE TABLE IF NOT EXISTS `test` (
`id` serial,
`path` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1; 

2 Comments

how do i add file path of multiple images in single row
You should not to this. One row - one path for one file.