I recently had to mass insert a really large text file of strings into MySQL. Here's how I did it.

Member Avatar
Member Avatar
+1 forum 1

SQL Insert India 'State'

Member Avatar
Member Avatar
+0 forum 5

first create the table [CODE] create table images ( image_id serial, filename varchar(255) not null, mime_type varchar(255) not null, file_size int not null, file_data longblob not null, primary key (image_id), index (filename) ); [/CODE] the file to output the images to the browser [B]picsrc.php[/B] [CODE]<?PHP //detect if image is called correctly if($image){ //connect to db $db = mysql_connect('localhost', 'user', 'password'); //find the image $query = sprintf('select * from images where filename = %d', $image); $result = mysql_query($query, $db); $image = mysql_fetch_array($result); //tell the browser the url is an image header('Content-type: ' . $image['mime_type']); header('Content-length: ' . $image['file_size']); //finally output the …

Member Avatar
Member Avatar
+0 forum 4

Here is a simple way to insert into a database that isn't much harder than using string concatenation - which we all know is very dangerous due to SQL injection attacks. Put the code snippet into `database.php`. Now, in a script handling a form post, such as `post_reply.php`: <?php require_once("database.php"); // Get session and post data to insert - no need for mysql_real_escape_string or other escaping // (Note: Passwords should still go through password_hash() or crypt() though!) $member_id = $_SESSION['member_id']; $response_to = isset($_POST['response_to']) ? $_POST['response_to'] : (isset($_GET['response_to']) ? $_GET['response_to'] : ''); $subject = isset($_POST['subject']) ? $_POST['subject'] : ''; $post = …

Member Avatar
Member Avatar
+4 forum 6

Raffle function to generate unique numbers for each player, related to the same table with a recursive aproach. I had to do a simple raffle system for a contest that I was working on and tried many things and the most simple and the most effective one to generate unique numbers for each player was this, a simple recursive function.

Member Avatar
Member Avatar
+0 forum 3

A while ago I explained how you could tag articles (see [this thread](http://www.daniweb.com/web-development/php/threads/387961/php-code-to-show-related-posts-on-a-blog)). Now you get a full working example. This code and the SQL script is also available on GitHub. The attached MySQL dump needs to be imported into your database, and you must update the credentials in the code below. I think the code is short enough to be read without comments. If this is not the case, feel free to ask questions.

Member Avatar
Member Avatar
+2 forum 1

Hi, - Why use paging? It's not really cool to print out all 2000 rows you have in a table to the page, so it'd be nice to page them. Special cases? Yeah, if you have 1000 rows.. and you've set the maximum row per page to 20, well.. you're gonna get 50 links for your pages.. so I took care of that. How? I only show the first costume number of page links, and the more you navigate, the more pages you'll see. Parameters: 1- The maximum number of results you want in each page. 2- The maximum number …

Member Avatar
Member Avatar
+6 forum 17

Below is a documented code example showing how to use the [MySQL functions](http://php.net/manual/en/book.mysql.php) to connect and query your database (and check for errors). Please note that using the MySQL extension is **NOT RECOMMENDED**. This extension is no longer maintained and will be deprecated soon. If you want your scripts to be future proof it is better to switch to [MySQLi](http://www.daniweb.com/web-development/php/code/434480/using-phpmysqli-with-error-checking) or [PDO](http://www.daniweb.com/web-development/php/code/435142/using-phppdo-with-error-checking). If there are any questions, or you want to see different features, let me know.

Member Avatar
+3 forum 0

I found an old thread that had never been answered here - [url]http://www.daniweb.com/software-development/vbnet/threads/330981[/url] Basically, the guy was asking how to retrieve database names and/or table names from a MySql database with vb.net. Here's my answer to that. Yes, I still use vb6 because vb.net is not much better and I can do anything I need to in vb6. This function is from a production program I wrote a while back. I looked all over Google to see if I could find a better way to do it but the examples I found were 'college level' and not real world code, …

Member Avatar
+0 forum 0

View the full tutorial at [URL="http://www.effectivewebdesign.co.nz/tutorial.php"]http://www.effectivewebdesign.co.nz/tutorial.php[/URL] I have tested this many times and it works fine. Please don't complain unless you really can't get it working, Just PM me and I'll fill in the blanks Happy Coding :)

Member Avatar
Member Avatar
+0 forum 3

[CODE]<?php /* +-----------------+------------------------------------------------------------+ | Class | setup | | Author | Brian Onang'o | | Version | 1.0 | | Last Modified | 10:16 AM 10/2/2010 GMT+3 | +-----------------+------------------------------------------------------------+ | This program is free software; you can redistribute it and/or | | modify it under the terms of the GNU General Public License | | as published by the Free Software Foundation; either version 2 | | of the License, or (at your option) any later version. | | | | This program is distributed in the hope that it will be useful, | | but WITHOUT ANY WARRANTY; without …

Member Avatar
Member Avatar
+0 forum 6

To view this tutorial with notes at [URL="http://www.effectivewebdesign.co.nz/tutorial.php"]http://www.effectivewebdesign.co.nz/tutorial.php[/URL] yes I am aware this is more php than mysql. howerver I get asked how to do it so often I thought I'd post it here aswell :)

Member Avatar
+0 forum 0

The End.