Unknown error in bind_param in mysql - mysql

Hi i got this error message on mysql query which has taken a toll of my time.
Fatal error: Uncaught Error: Call to a member function bind_param() on unknown in ...
Anyone encounter this unknown error before?
How can mysql display the error?
Below is my query:
($db->prepare('INSERT INTO program_list(
PROGRAM_CODE_ID, MONTH, PDATE, HOURS, PUNIQUE, AUNIQUE,
EYEBALL, LEVEL, REMARK, REVENUE, TRAINER_ID, CLIENT_ID, ADMIN_ID, UPD_TIME) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)')) || fail('MySQL prepare', $db->error);
$stmt->bind_param('ssssssssssssss', $program_code, $month, $pdate, $hours, $unique, $adult, $eyeball, $lvl, $remark, $revenue, $trainer_id, $client_id, $admin_id, $time) || fail('MySQL bind_param', $db->error);
I did the echo of the query with variables and able to execute the query successfully on phpmyadmin.

Related

What if too many parameters in mysql query in node.js

This table has many parameters, and when i do insert it's like this, (... is for demo propose)
const sqlCmd = `insert into Consumer (key, secret, ..., version)
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;
try {
const param = [myTable.key, myTable.secret, ..., myTable.version];
return await dbPool.execSqlCmd(sqlCmd, param)
}
Is there a way to avoid so many ?s ?
In SQL, you use one ? parameter placeholder for each scalar value you want to pass to the SQL statement. No more, no less.
If you want fewer ? placeholders, then you must pass fewer parameters. You can do this by:
Omitting some columns from the INSERT statement. The row inserted will use the DEFAULT value declared for the column, or else NULL if there is no default.
Using a constant expression in the VALUES clause for some columns, instead of a parameter. I mean this can be a constant literal, like a numeric or string or date, or it can be an expression or function, which will be evaluated, and the resulting value used for the INSERT.

how to solve unexpected token using MySQL Hibernate?

Im getting below error
org.hibernate.hql.internal.ast.QuerySyntaxException:unexpected token values: values near line 1, column 161 .
[insert into shop_information(storeName, ownername, license, email, dlnumber, gst, pan, pincode, phonenumber, mobile, fax, cst, phone, district, state, country) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]
You have to use
session.createSQLQuery(SQL_QUERY);
not
session.createQuery(SQL_QUERY);
HQL only supports insert from another table.
e.g.
INSERT INTO Entity properties_list select_statement.
If you wan't to use standard insert statement like
INSERT INTO Table properties_list values ( :vals)
you need
session.createSQLQuery(SQL_QUERY)
Edit, to answer the comment:
I think that the parameters are 0-based, so try to start the parameters from 0:
query.setParameter(0,storeName);
query.setParameter(1,ownerName);
etc...
However the better way is to use named parameters:
sessionFactory.getCurrentSession()
.createSQLQuery("update table set field = 1 where id = :id")
.setParameter("id", someId)
.executeUpdate();

Issue in inserting values to table through jsp

I got this exception while using one of the answers from stackoverflow.
You can't specify target table 'tablename' for update in FROM clause
This is my query and am using JSP to pass queries:
String queryString = "INSERT INTO tablename(SL_No,candidate,phone,pan,mailid)
VALUES(SELECT (MAX(SL_No)+1 newSL_No from tablename), ?, ?, ?, ? ))";
Thanks in advance.
INSERT INTO tablename(SL_No,candidate,phone,pan,mailid)
select MAX(SL_No) + 1, ?, ?, ?, ?
from tablename
But actually it looks like you could just use the auto-increment of the SQL engine to do MAX(SL_No) + 1. If you change to column to that then your statement would be
INSERT INTO tablename(candidate,phone,pan,mailid)
values (?, ?, ?, ?)

Syntax error mysql

Where is the syntax error in this statement? I dont get it, can I use the "? bind param method" in this case? I use PDO
$stmt = $dbh->prepare("INSERT INTO epinfo WHERE TVShowTitle=? (Season, Episode, SDLink, HDLink, DlSDLink, DlHDLink) VALUES (?, ?, ?, ?, ?, ?)");
$stmt->bindParam(1, $_POST[tvshow]);
$stmt->bindParam(2, $_POST[season]);
$stmt->bindParam(3, $_POST[episode]);
$stmt->bindParam(4, $_POST[sdlink]);
$stmt->bindParam(5, $_POST[hdlink]);
$stmt->bindParam(6, $_POST[dlsdlink]);
$stmt->bindParam(7, $_POST[dlhdlink]);
$stmt->execute();
Error message:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE TVShowTitle='Breaking Bad' (Season, Episode, SDLink, HDLink, DlSDLink, DlH' at line 1
The standard INSERT syntax has no WHERE clause. I think you want to UPDATE your existing record.
UPDATE epinfo
SET Season = ?,
Episode = ?,
SDLink = ?,
HDLink = ?,
DlSDLink = ?,
DlHDLink = ?
WHERE TVShowTitle=?
INSERT INTO epinfo (TVShowTitle, Season, Episode, SDLink, HDLink, DlSDLink, DlHDLink) VALUES (?, ?, ?, ?, ?, ?, ?)"
You need to remove the where clause.
from here
INSERT INTO epinfo WHERE
Try like this:-
INSERT INTO epinfo(Season, Episode, SDLink, HDLink, DlSDLink, DlHDLink)
VALUES (?, ?, ?, ?, ?, ?)
From your comments:
If you want to update the value then use it like this:-
update epinfo
set column = "value"
where TVShowTitle=?

hibernate 3.2.6 or 3.3.2 and jboss 4.2.3.GA deployed app run fails with c3p0 error

I deploy app having hibernate dependency.
Jboss AS 4.2.3.GA contains hibernate3.jar in server/default/lib.
Tried to load SessionFactory and and get.
With
java.lang.ClassNotFoundException: No ClassLoaders found for: org.hibernate.connection.C3P0ConnectionProvider
at org.jboss.mx.loading.LoadMgr3.beginLoadTask(LoadMgr3.java:306)
at org.jboss.mx.loading.RepositoryClassLoader.loadClassImpl(RepositoryClassLoader.java:521)
at org.jboss.mx.loading.RepositoryClassLoader.loadClass(RepositoryClassLoader.java:415)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:192)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:96)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:79)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:425)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:89)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2119)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2115)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1339)
Googled it with no result.
Substitute hibernate3.jar with hibernate-3.2.6.ga.
and SessionFactory loading hangs somewhere at
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1339)
at loading of mapping.
2013-05-21 11:42:27,824 DEBUG [org.hibernate.persister.entity.AbstractEntityPersister] Insert 0: insert into cb_entity (HOST, response_url, ADM_STATE, PORT, SYSTEM_ID, PASSWD, ADDRESS_RANGE, TON, NPI, LINK_TYPE, BIND_HOST, BIND_PORT, NAME, DESCRIPTION, OWNER, ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2013-05-21 11:42:27,824 DEBUG [org.hibernate.persister.entity.AbstractEntityPersister] Update 0: update cb_entity set HOST=?, response_url=?, ADM_STATE=?, PORT=?, SYSTEM_ID=?, PASSWD=?, ADDRESS_RANGE=?, TON=?, NPI=?, LINK_TYPE=?, BIND_HOST=?, BIND_PORT=?, NAME=?, DESCRIPTION=?, OWNER=? where ID=?
2013-05-21 11:42:27,824 DEBUG [org.hibernate.persister.entity.AbstractEntityPersister] Delete 0: delete from cb_entity where ID=?
2013-05-21 11:42:27,835 DEBUG [org.hibernate.persister.entity.AbstractEntityPersister] Static SQL for entity: com.alt1.cbc.core.BaseStationSubsystem
2013-05-21 11:42:27,835 DEBUG [org.hibernate.persister.entity.AbstractEntityPersister] Version select: select id from bss where id =?
2013-05-21 11:42:27,835 DEBUG [org.hibernate.persister.entity.AbstractEntityPersister] Snapshot select: select basestatio_.id, basestatio_.parent_id as parent2_0_, basestatio_.type as type0_, basestatio_.name as name0_, basestatio_.description as descript5_0_, basestatio_.bsc_admin_state as bsc6_0_, basestatio_.bsc_id as bsc7_0_, basestatio_.OWNER as OWNER0_, basestatio_.PARAMS as PARAMS0_, basestatio_.operator as operator0_ from bss basestatio_ where basestatio_.id=?
2013-05-21 11:42:27,835 DEBUG [org.hibernate.persister.entity.AbstractEntityPersister] Insert 0: insert into bss (parent_id, type, name, description, bsc_admin_state, bsc_id, OWNER, PARAMS, operator, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Data model class file depended on class which during build was copied to WEB-INF/classes instead of jar.