नहीं बना रहा है, तो मैं एक नाम, संख्या और कंपनी को डीबी में डाल रहा हूं।मौजूद होने पर एक पंक्ति अपडेट करें, यदि कोई नया MySQL
मेरे तालिका बस है:
id(primary key)
name
slideView
company
मैं अगर एक नाम से पारित कर दिया यह जानकारी अपडेट करने यह मौजूद है, यदि इस डेटा के साथ एक नई पंक्ति नहीं बना की जरूरत है। मैंने REPLACE INTO
पर देखा है लेकिन मुझे नहीं लगता कि यह मेरे लिए काम करेगा ... क्योंकि मैं आईडी को बिल्कुल स्पर्श नहीं करता हूं।
मेरे कोड है:
insertData($name,$count,$company);
function insertData($name, $count, $company) {
#Try/Catch statement to connect to DB, and insert data
try {
#DB username/password
$usernameDB = '****';
$passwordDB = '****';
#Create new PHP Database Object with the address, username, and password as parameters
$pdo = new PDO('mysql:host=localhost;dbname=*****', $usernameDB, $passwordDB);
#Set pdo attributes to handle errors
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
#assign the sth variable (sth means statement handle) to insert the data
$sth = $pdo->prepare("REPLACE INTO ***** SET name = ?, slideView = ?, company = ?");
#Execute the insert
$sth->execute(array($name,$count,$company));
#Error if can't connect or insert
} catch(PDOException $e) {
echo 'Error: ' . $e->getMessage();
}#/try
}
मैं एसक्यूएल और havnt के लिए नया हूँ अभी तक यह करने के लिए एक अच्छा रास्ता मिल गया।
मैंने मूल रूप से जो कुछ भी किया था उस पर वापस जाना चुना। एक बार मैंने अपना नाम कॉलम अद्वितीय चिह्नित किया। धन्यवाद! – mdance