am trying to insert multiple raw data using foreach and for loop. script work properly. am using pdo insert data to mysql.
insert work properly but have a big problem. no error reporting. php 5.4 mysql 5.5 - var1 = 'man', var2 = '1', var3 = 'a'
-
var1 = 'gt', var2 = '1', var3 = 'a'
-
var1 = 'cook', var2 = '1', var3 = 'a'
-
mysql table - var1 varchar(50) not null unique,
-
var2 varchar(50) not null,
-
var3 tinytext not null
-
am suppose - var1 var2 var3
-
man 1 a
-
gt 1 a
-
cook 1 a
-
but its works like this <space> mean just space - var1 var2 var3
-
<space> 1 a
-
<space> 1 a
-
cook 1 a
-
last one inserting properly. others not working. help me
2 1993
Can't really help without seeing your code.
//firstly thanks for rabit
//script php - $words = array('man','pan','can');
-
foreach($words as $var1){
-
var2 = 1;
-
var3 = a;
-
-
$obj = new myclass( array(
-
"var1"=> isset( $var1 ) ? (string) $var1 :"",
-
"var2"=> isset( $var2 ) ? (string) $var2 :"",
-
"var3"=> isset( $var3 ) ? (string) $var3 :"",
-
) );
-
-
$obj->insert();
-
}
-
-
//class myclass
-
-
class myclass extends DObject {
-
protected $data = array(
-
"var1" => "",
-
"var2" => "",
-
"var3" => ""
-
);
-
-
public function insert() {
-
$conn = parent::connect();
-
$sql = "INSERT INTO " . TBL_MYTBL . " (
-
var1,
-
var2,
-
var3
-
) VALUES (
-
:var1,
-
:var2,
-
:var3
-
)";
-
try {
-
$st = $conn-> prepare( $sql );
-
$st-> bindValue( ":var1", $this-> data["var1"], PDO::PARAM_STR );
-
$st-> bindValue( ":var2", $this-> data["var2"], PDO::PARAM_STR );
-
$st-> bindValue( ":var3", $this-> data["var3"], PDO::PARAM_STR );
-
$st-> execute();
-
parent::disconnect( $conn );
-
} catch ( PDOException $e ) {
-
parent::disconnect( $conn );
-
die( "Query failed: " . $e-> getMessage() );
-
}
-
}
-
-
}
-
-
//dobject class
-
-
abstract class DObject {
-
protected $data = array();
-
-
public function __construct( $data ) {
-
foreach ( $data as $key => $value ) {
-
if ( array_key_exists( $key, $this-> data ) ) $this-> data[$key] = $value;
-
}
-
}
-
protected static function connect() {
-
try {
-
$conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
-
$conn-> setAttribute( PDO::ATTR_PERSISTENT, true );
-
$conn-> setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
-
} catch ( PDOException $e ) {
-
die( "Connection failed: " . $e-> getMessage() );
-
}
-
return $conn;
-
}
-
-
protected static function disconnect( $conn ) {
-
$conn = "";
-
}
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics
by: jason |
last post by:
How does one loop through the contents of a form complicated by dynamic
construction of checkboxes which are assigned a 'model' and 'listingID' to
the NAME field on the fly in this syntax:...
|
by: Duane Winner |
last post by:
Hello all -
I'm having a small problem with the mysql startup script that ships with
MySQL-3.23.56-1.
I'm running on RedHat Linux.
It works fine, but I have a backup server that runs a script...
|
by: Michael Schoen |
last post by:
Hi there,
i=B4m actually developing a performance criticial system where I need to
index a huge amount of protocoll data.
These data are already in a chronological order, so if I push the data...
|
by: gw |
last post by:
I am new to MySQL and my problem is with storing a datetime value in a
table. I created a table with a column designated as DATETIME. I
fill it with the NOW() function. No matter whether I...
|
by: Leslaw Bieniasz |
last post by:
Cracow, 20.09.2004
Hello,
I need to implement a library containing a hierarchy of classes
together with some binary operations on objects. To fix attention,
let me assume that it is a...
|
by: Asha |
last post by:
greetings, i'm doing a multiple insert into the db through a store proc. i'm
very sure the sp has nothing wrong. below are my implementation code and
error msg. thanks in advance for the help
...
|
by: wesley |
last post by:
Can i make multiple inserts into a table using one statement.
the statement:
INSERT INTO table1 (UserName) VALUES (SELECT DISTINCT UserName FROM
table2)
Basically, i want to take out all the...
|
by: Brad Baker |
last post by:
I'm trying to write a simple asp.net page which updates some data in a SQL
database. At the top of the page I have the following code:
<%@ Page Language="C#" Debug="true" %>
<%@ import...
|
by: clayalphonso |
last post by:
Here is the code:
<%
dim testArray, testArray2
dim Conn, rs
dim sSQL, sConnString
'response.write request.form("sel1")
'testArray = split(request.form("sel1"),",")
'for each gidstuff In...
|
by: bonneylake |
last post by:
Hey Everyone,
Well recently i been inserting multiple fields for a section in my form called "serial". Well now i am trying to insert multiple fields for the not only the serial section but also...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| | |